<?php
function select_admin($option){
    global $db; 
    $query = "SELECT * FROM articles ";
    $data = $db->query($query) or die('Loi truy van');
    return $data;
}
 
function add_admin($id,$title,$overview,$body,$id_category){
  global $db;
  $sql = "INSERT INTO articles(id, title, overview, body, id_category)
                            VALUES('','$title','$overview','$body','$id_category')";
  $db->exec($sql) or die('Loi truy van');
  echo 'Them thanh cong';
}
 
function del_admin($id){
    global $db;
    $sql = "DELETE FROM articles WHERE id = '$id'";
    $db->exec($sql) or die('Loi truy van');
    echo 'Xoa thanh cong.';
    header('Location:admin.php');
}
function edit_admin($id,$title,$overview,$body,$id_category){
    global $db;
    $query = "UPDATE articles SET title='$title',
        overview = '$overview',body='$body',id_category = '$id_category' 
        WHERE id = '$id'";
    $db->exec($query) or die('Loi truy van');
    echo 'Sua thanh cong.';
    header('Location:admin.php');
}
?>